import java.util.Stack;

import java.util.Stack;
class Solution1 {
    public boolean backspaceCompare(String s, String t) {
        Stack<Character> stacks = new Stack<>();
        Stack<Character> stackt = new Stack<>();
        for(Character a:s.toCharArray()) {
            if(a!='#') {
                stacks.push(a);
            } else if(!stacks.isEmpty()&&a=='#') {
                stacks.pop();
            }
        }for(Character a:t.toCharArray()) {
            if(a!='#') {
                stackt.push(a);
            } else if(!stackt.isEmpty()&&a=='#') {
                stackt.pop();
            }
        }
        while (!stacks.isEmpty() && !stackt.isEmpty()) {
            if (stacks.pop() != stackt.pop()) {
                return false;
            }
        }
        return stacks.isEmpty() && stackt.isEmpty();
    }
}
public class lc844 {
}
